package com.example.sqlitetest.domain;

import com.example.sqlitetest.converter.LocalDateTimeAttributeConverter;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author ch
 * @date 2022/7/6
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name="customer_order")
public class ExpressOrder {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column(name = "id", nullable = false, length = 20)
    private Long id;
    @Column(length = 20, nullable = false, name = "order_id")
    private String orderId;
    /** 旺旺号/店铺名 */
    @Column(length = 64)
    private String wangwangName;
    /** 客户名称 */
    @Column(length = 64)
    private String customerName;
    @Column(length = 64)
    private String remark;
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Convert(converter = LocalDateTimeAttributeConverter.class)
    private LocalDateTime createTime;
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Convert(converter = LocalDateTimeAttributeConverter.class)
    private LocalDateTime updateTime;
    @Transient
    private Integer orderType = 0;
    @Transient
    private String alertContent;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
            return false;
        }
        ExpressOrder that = (ExpressOrder) o;
        return id != null && Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }

//    public String getCreateTime() {
//        if (createTime != null) {
//            return DateUtil.getStringDate(createTime);
//        }
//        return "";
//    }
}
